<template>
	<el-container>
		<el-header style="height: auto;">
			<sc-select-filter :data="filterData" :label-width="80" @on-change="filterChange"></sc-select-filter>
		</el-header>
		<el-header>
			<div class="left-panel">
			</div>
			<div class="right-panel">
				<div class="right-panel-search">
					<el-input v-model="search.keyword" placeholder="标题 / 摘要"></el-input>
					<el-button type="primary" icon="el-icon-search" @click="upsearch"></el-button>
				</div>
			</div>
		</el-header>
		<el-main class="nopadding">
			<scTable ref="table" :apiObj="apiObj" row-key="planId" stripe remoteSort remoteFilter>
				<el-table-column label="#" type="index" width="50"></el-table-column>
				<el-table-column label="计划标题" prop="title" width="300" :show-overflow-tooltip="true"></el-table-column>
				<el-table-column label="计划摘要" prop="subheading" width="400" :show-overflow-tooltip="true"></el-table-column>
				<el-table-column label="计划类型" prop="planTypeName" width="100"></el-table-column>
				<el-table-column label="开始时间" prop="beginTime" width="150"></el-table-column>
				<el-table-column label="结束时间" prop="endTime" width="150"></el-table-column>
				<el-table-column label="当前状态" prop="status" width="100">
					<template #default="scope">
						<el-button type="primary" size="small" v-if="scope.row.status==='0'">进行中</el-button>
						<el-button type="success" size="small" v-else-if="scope.row.status==='1'">已结束</el-button>
						<el-button type="danger" size="small" v-else-if="scope.row.status==='2'">已挂起</el-button>
						<el-button type="info" size="small" v-else>未知</el-button>
					</template>
				</el-table-column>
				<el-table-column label="负责人" prop="holdUserName" width="100"></el-table-column>
				<el-table-column label="督查人" prop="supUserName" width="100"></el-table-column>
				<el-table-column label="操作" fixed="right" align="right" width="170">
					<template #default="scope">
						<el-button-group>
							<el-button text type="primary" size="small" @click="table_show(scope.row, scope.$index)">查看</el-button>
							<el-button text type="primary" size="small" @click="table_edit(scope.row, scope.$index)" v-if="scope.row.status=='0'">反馈</el-button>
						</el-button-group>
					</template>
				</el-table-column>
			</scTable>
		</el-main>
	</el-container>
	<save-dialog v-if="dialog.save" ref="saveDialog" @success="handleSaveSuccess" @closed="dialog.save=false"></save-dialog>
	<work-plan-details v-if="dialog.detailsSave" ref="workPlanDetailsDialog" @closed="dialog.detailsSave=false"></work-plan-details>
</template>

<script>
import scSelectFilter from '@/components/scSelectFilter'
import WorkPlanDetails from "@/views/office/workplan/workPlanDetails";
import saveDialog from './save'
export default {
	name: 'My Work Plan',
	components: {
		WorkPlanDetails,
		scSelectFilter,
		saveDialog
	},
	data() {
		return {
			dialog: {
				save: false,
				detailsSave:false
			},
			filterData: [
				{
					title: "日期范围",
					key: "date",
					multiple: false,
					options: [
						{
							label: "全部",
							value: ""
						},
						{
							label: "今日",
							value: "1"
						},
						{
							label: "昨日",
							value: "2"
						},
						{
							label: "一周内",
							value: "3"
						},
						{
							label: "一月内",
							value: "4"
						},
						{
							label: "一月前",
							value: "5"
						}
					]
				},
				{
					title: "计划类型",
					key: "planType",
					multiple: false,
					options:[{
						label: "全部",
						value: ""
					}]
				},
				{
					title: "当前状态",
					key: "status",
					multiple: false,
					options: [{
						value: '',
						label: '全部'
					},{
						value: '0',
						label: '进行中'
					},{
						value: '1',
						label: '已结束'
					},{
						value: '2',
						label: '已挂起'
					}],
				},
				{
					title: "计划范围",
					key: "type",
					multiple: false,
					options: [{
						value: '0',
						label: '我参与的'
					},{
						value: '1',
						label: '分享给我的'
					}],
				}
			],
			apiObj: this.$API.office.workPlan.getMyWorkPlanList,
			search: {
				type:'0',
				date:'',
				workPlan:'',
				status:'',
				keyword: null
			}
		}
	},
	mounted() {
		this.getSysDicByCode();
	},
	methods: {
		async getSysDicByCode()
		{
			var res = await this.$API.system.sysDic.getSysDicByCode.get({code:'workPlan'});
			if (res.code == 200) {
				this.filterData[1].options=this.filterData[1].options.concat(res.data);
			} else {
				this.$alert(res.message, "提示", {type: 'error'})
			}
		},
		//查看
		table_show(row) {
			this.dialog.detailsSave = true
			this.$nextTick(() => {
				this.$refs.workPlanDetailsDialog.open().setData(row);
			})
		},
		table_edit(row)
		{
			this.dialog.save = true
			this.$nextTick(() => {
				this.$refs.saveDialog.open().setData(row);
			})
		},
		//搜索
		async upsearch() {
			this.$refs.table.upData(this.search)
		},
		filterChange(data){
			this.search.type = data.type;
			this.search.date = data.date;
			this.search.planType = data.planType;
			this.search.status = data.status;
			this.$refs.table.upData(this.search)
		},
		//本地更新数据
		handleSaveSuccess() {
			this.$refs.table.refresh()
		}
	}
}
</script>

<style>
</style>
